﻿@model IEnumerable<Developer.Entity.User>
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    int i = 1;
}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 消息管理 <span class="c-gray en">&gt;</span> 选择用户 <a class="btn btn-success radius r" id="btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <form id="searchForm" action="/admin/message/chooseUsers" method="get">
            <input type="text" class="input-text" style="width: 250px" placeholder="输入人员账号" id="username" name="name" value="@ViewBag.Name">
            <button type="submit" class="btn btn-success radius"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="batsend()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量发送</a> </span> <span class="l"><a href="javascript:;" onclick="batsendalluser()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 全员发送</a> </span> <span class="r">共有数据：<strong>@ViewBag.itemCount</strong> 条</span> </div>
    <div class="mt-20">
        <input type="hidden" name="content" value="@ViewBag.contents"id="content"/>
        <input type="hidden" name="title" value="@ViewBag.title" id="title"/>
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
                <tr class="text-c">
                    <th><input type="checkbox" name="" value=""></th>
                    <th>序号</th>
                    <th>账号</th>
                    <th>是否绑定微信</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr class="text-c">
                        <td><input type="checkbox" value="@item.Id" name="checkedList"></td>
                        <td id="companyId">@(i++)</td>
                        <td>@item.Account</td>
                        <td>@(item.WeChats.Count > 0 ? "是" : "否")</td>
                        <td>@item.CreateTime</td>
                        <td class="td-manage">
                            <a title="发送" href="javascript:;" onclick="singlesend(@item.Id)" class="ml-5 btn btn-primary radius" style="text-decoration: none" id="sendid@(item.Id)">发送</a>
                            @if (item.WeChats.Count > 0)
                            {
                                <a title="微信详情" href="javascript:;" onclick="sf_show('微信详情', '/admin/user/wechatdetail/?Id=@item.WeChats.FirstOrDefault().Id', '', '420', true)" class="ml-5 btn btn-primary radius" style="text-decoration: none">微信详情</a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <div id="adminPage"></div>
        <div style="clear:both;"></div>
    </div>
</div>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
    sf_page('adminPage', @ViewBag.pageCount);

    function batsend() {
        $.ajax({
            url: '/Message/ChooseBatUser',
            type: 'POST',
            dataType: 'Json',
            data: { 'content': $('#content').val(), 'title': $('#title').val() },
            success: function (data) {
                if (data.hasOwnProperty('error')) {
                    layer.confirm(data['error'], function () { });
                } else {
                    layer.confirm(data['success'], function () { });
                }
            }
        });
    }

    function singlesend(uid) {
        $.ajax({
            url: '/Message/ChooseBatUser',
            type: 'POST',
            dataType: 'Json',
            data: { 'content': $('#content').val(), 'title': $('#title').val(), 'uid': uid },
            success: function (data) {
                if (data.hasOwnProperty('error')) {
                    layer.confirm(data['error'], function () { });
                } else {
                    var sendid = '#sendid' + uid;
                    $(sendid).attr('disabled', 'disabled');
                    layer.confirm(data['success'], function () { });
                }
            }
        });
    }

    function batsendalluser() {
        $.ajax({
            url: '/Message/ChooseAllUser',
            type: 'POST',
            dataType: 'Json',
            data: { 'content': $('#content').val(), 'title': $('#title').val()},
            success: function (data) {
                if (data.hasOwnProperty('error')) {
                    layer.confirm(data['error'], function () { });
                } else {
                   // var sendid = '#sendid' + uid;
                   // $(sendid).attr('disabled', 'disabled');
                    layer.confirm(data['success'], function () { });
                }
            }
        });
    }
</script>
